"""A utils colection for serial port management"""
import serial

def scan():
    """scan for available ports. return a list of tuples (num, name)"""
    available = []
    for i in range(256):
        try:
            s = serial.Serial(i)
            available.append( (i, s.name))
            s.close()   # explicit close 'cause of delayed GC in java
        except serial.SerialException:
            pass
    return available

if __name__ == '__main__':
    print "Found ports:"
    for number, name in scan():
        print "(%d) %s" % (number, name)
